package com.yanqu.road.server.manager.activity.sonhai.handler.impl;

import com.yanqu.road.entity.activity.sonhai.data.SonHaiPlotData;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.entity.rank.yrank.UserYRank;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiTeam;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiUser;
import com.yanqu.road.server.manager.activity.sonhai.handler.IPlotTypeHandler;
import com.yanqu.road.server.manager.activity.sonhai.handler.entity.PlotTypeHandlerExploreReq;
import com.yanqu.road.server.manager.activity.sonhai.handler.entity.PlotTypeHandlerExploreResp;
import com.yanqu.road.utils.ListHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * 营地
 */
public class PlotType14Handler implements IPlotTypeHandler {

    /**
     * logger
     */
    private static Logger logger = LogManager.getLogger(PlotType14Handler.class.getName());

    /**
     * 探索后处理
     * @param req
     * @return
     */
    @Override
    public PlotTypeHandlerExploreResp explore(PlotTypeHandlerExploreReq req) {
        CrossSonHaiUser user = req.getUser();;
        CrossSonHaiActivity activity = req.getActivity();
        SonHaiPlotData plotData = req.getPlotData();
        //获取PVP目标用户列表
        List<UserYRank> fiterRankList = activity.getRandomPvpPool(user);
        if (fiterRankList == null || fiterRankList.isEmpty()) {
            logger.error("山海伏兽-探索-营地事件：排行榜随机为空，{},{}", user.getUserId(), fiterRankList);
            return null;
        }
        //随机出一个
        UserYRank userRank = ListHelper.getRandomElement(fiterRankList);
        //获取target玩家数据
        CrossSonHaiUser targetUser = activity.getUser(userRank.getUserId());
        if (targetUser == null) {
            logger.error("山海伏兽-探索-营地事件：目标玩家不存在，{}", userRank.getUserId());
            return null;
        }
        //地块注入目标玩家
        plotData.setPvpUserId(targetUser.getUserId());
        //目标玩家添加攻击者地块
        targetUser.addAttackMeUserPlot(plotData);
        return null;
    }
}
